<?
$url = 'http://pda.atnext.com/isilo/pda_login.cfm?aToken='.$token;
?>

<? echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>
<?xml-stylesheet type=\"text/css\" href=\"style.css\" ?>
");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<meta http-equiv="Content-Type" content="text/xml; charset=utf-8" />
<title><? echo $appname; ?></title>
<link rel="apple-touch-icon" href="inext.png" />
<meta name="apple-touch-fullscreen" content="YES" />
<style type="text/css" media="screen">@import "<? echo $iui_url; ?>/iui.css";</style>
<style type="text/css" media="screen">
body > .toolbar {
  height: 40px;
}
.toolbar > h1 {
  height: 40px;
  font-size: 18px;
}
body > ul > li {
  font-size: 18px;
}
body > ul > li > a {
  padding: 6px 32px 6px 10px;
}
p {
  margin: 10px;
}
</style>
<script type="application/x-javascript" src="<? echo $iui_url; ?>/iui.js"></script>
<script type="application/x-javascript">
window.iui animOn = true;
</script>
</head>
<body>

<?
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, 0);
set_curl_useragent($curl);
$str = curl_exec($curl);
curl_close($curl);

echo '<div class="toolbar">';
echo '  <h1 id="pageTitle"></h1>';
echo '  <a id="backButton" class="button" href="#"></a>';
echo '</div>';
echo '<ul title="'.$appname.'" selected="true">';

while ($str) {
  $line = el_iextract($str, '<a ', '</a>', true);
  $str = el_iextract(el_iextract($str, '</a>'), '<a ', '', true);

  if (strpos($line, 'pdatop.gif')) {
    continue;
  }

  if ($line) {
    $line = str_replace('<br>', '', $line);
    if (preg_match('/ href="([^"]+)"/', $line, $res) > 0) {
      $href = $res[1];
      if (strpos($href, 'NextMagazine.cfm') === false &&
          strpos($href, 'Face.cfm') === false &&
          strpos($href, 'EasyFinder.cfm') === false &&
          strpos($href, 'SuddenWeekly.cfm') === false &&
          strpos($href, 'EatTravelWeekly.cfm') === false &&
          strpos($href, 'Ketchup.cfm') === false &&
          strpos($href, 'MeWeekly.cfm') === false)
      {
        $param = '';
      }
      else {
        $param = 'level=1&amp;';
      }
      // remove token from url
      $newhref = preg_replace('/[\?|&]aToken=[^&]*/', '', $href);
      $line = str_replace($href, 'list.php?'.$param.'u='.urlencode($newhref), $line);
    }
    $line = iconv('BIG5', 'UTF-8', $line);
    echo '<li>'.$line.'</li>';
  }
}

echo '</ul>';
?>
</body>
</html>